package rouler.action.partycasino.european;

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import rouler.roulette.Colors;

public class RouletteAction {

	Robot rob;
	
	public RouletteAction(){
		try {
			rob = new Robot();
			rob.setAutoDelay(220);
//			rob.setAutoWaitForIdle(true);
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}
	
	public void bet(Colors color){
		if(color.equals(Colors.black)){
			betBlack();
		}else{
			betRed();
		}
	}
	
	public void betRed(){
		System.out.println("bet red");
		rob.keyPress(KeyEvent.VK_7);
	}
	
	public void betBlack(){
		System.out.println("bet black");
		rob.keyPress(KeyEvent.VK_8);
	}
	
	public void spin(){
		rob.mouseMove(970,650);
		rob.mousePress(InputEvent.BUTTON1_MASK);
	    rob.mouseRelease(InputEvent.BUTTON1_MASK);
	}
	
	public void rebet(){
		rob.mouseMove(800,669);
		rob.mousePress(InputEvent.BUTTON1_MASK);
	    rob.mouseRelease(InputEvent.BUTTON1_MASK);
	}
	
	public void doubleBet(){
		rob.mouseMove(877,669);
		rob.mousePress(InputEvent.BUTTON1_MASK);
	    rob.mouseRelease(InputEvent.BUTTON1_MASK);
	}
	
	public boolean isSpinning(){
		Color color = rob.getPixelColor(700, 332);
		return color.getBlue()+color.getRed()+color.getGreen()>12;
	}
	
	public Colors getColor(){
		Color color = rob.getPixelColor(95, 145);
		if(color.getGreen()>200)return Colors.green;
		if(color.getRed()>200)return Colors.red;
		return Colors.black;
	}
}
